home *** CD-ROM | disk | FTP | other *** search
/ Amiga Plus 2002 #11 / Amiga Plus CD - 2002 - No. 11.iso / Tools / Development / TinyGL / ami / content / ad709 / tinygl / examples / c / triangle.c < prev   
Encoding:
C/C++ Source or Header  |  2002-08-15  |  1.3 KB  |  67 lines

  1. /*************************************
  2. *  Drawing a triangle
  3. *
  4. ************/
  5.  
  6. #include <stdio.h>
  7. #include <stdlib.h>
  8. #include <ad709/tinygl/glut.h>
  9.  
  10.  
  11. int glutWindow;
  12.  
  13.  
  14. void init(void)     {
  15.     glEnable(GL_DEPTH_TEST);
  16.     glShadeModel(GL_FLAT);
  17.     glClearColor(0.0, 0.0, 0.0, 0.0) ;
  18. }
  19.  
  20.  
  21. void reshape(int width, int height) {
  22.     glViewport(0, 0, (GLint) width, (GLint) height);
  23.     glMatrixMode(GL_PROJECTION);
  24.     glLoadIdentity();
  25.     glFrustum(-2.0, 2.0, -2.0, 2.0, 6.0, 20.0);
  26.     glMatrixMode(GL_MODELVIEW);
  27.     glLoadIdentity();
  28.     glTranslatef(0.0, 0.0, -8.0);
  29. }
  30.  
  31.  
  32. void display(void)    {
  33.     glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
  34.     glPushMatrix();
  35.     glTranslatef(-1.0, 0.0, 0.0);
  36.     glRotatef(0, 0.0, 0.0, 1.0);
  37.     glBegin(GL_TRIANGLES);
  38.         glColor3f(1.0f, 0.0f, 0.0f);
  39.         glVertex2f(0, -0.5);
  40.         glColor3f(0.0f, 1.0f, 0.0f);
  41.         glVertex2f(1.0, 1.0);
  42.         glColor3f(0.0f, 0.0f, 1.0f);
  43.         glVertex2f(-1.0, 1.0);
  44.     glEnd();
  45.     glPopMatrix();
  46. }
  47.  
  48.  
  49. void idle() {
  50.     glutPostRedisplay();
  51. }
  52.  
  53.  
  54. int main(int argc, char** argv)    {
  55.     glutInit(&argc, argv);
  56.     glutInitWindowSize(320, 240);
  57.     glutInitWindowPosition(0, 0);
  58.     glutWindow = glutCreateWindow("OpenGL triangle");
  59.     init();
  60.     glutDisplayFunc(display);
  61.     glutReshapeFunc(reshape);
  62.     glutIdleFunc(idle);
  63.     glutMainLoop();
  64.  
  65.     return 0 ;
  66. }
  67.